#include "gaia_common.h"
#include "gaia_db.h"

//DB_MYSQL gaia_connect_mysql(void);
int gaia_connect_mysql(MYSQL **mysql);
/*
//just test
int main(void)
{
  MYSQL *mysql;

  gaia_connect_mysql(&mysql); 
  if(NULL != mysql)
   fprintf(stderr,"mysql connect success!\n");
  else{
   fprintf(stderr,"mysql connect fail!\n");
   return 1;
  }
  return 0;
}
*/
/* 函数功能：创建与mysql的连接 
 * 返回值：mysql的文件句柄或者NULL
*/
int gaia_connect_mysql(MYSQL **mysql)
{

   /* mysql初始化 */
  *mysql = mysql_init(NULL);

  //if(!mysql_real_connect(mysql,data->host,data->dbname,data->dbuser,data->dbpasswd,strtoul(data->dbport,NULL,10),NULL,0))
  if(!mysql_real_connect(*mysql,DB_HOST,DB_USER,DB_PASS,DB_NAME,DB_PORT,NULL,0))
  {
    fprintf(stderr,"Can't connect MySQL %s\n",mysql_error(*mysql));
    return 1;
  }
 
  return 0;
}
